﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>外委统计看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-form-item__label {
      color: #fff;
    }

    .header-title {
      font-size: 24px;
    }

    .el-form-item {
      margin-bottom: 0 !important;
    }

    .el-dialog__title {
      text-align: center !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <!-- 看板标题组件 -->
      <vue2-board-header :title="title"></vue2-board-header>
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :label-position="'left'" :rules="rules"
        style="margin:5px 0px 0px 5px;">
        <el-form-item label="主制分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择" filterable @change="factorySeletChange">
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="外委厂家:">
          <el-select v-model="queryInfo.customerid" placeholder="请选择" filterable clearable>
            <el-option v-for="f in customerList" :key="f.customerid" :label="f.customername" :value="f.customerid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="外委时间:" prop="selectdate">
          <el-date-picker v-model="queryInfo.selectdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="handlerBtnSearch">查询</el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 图表 -->
      <el-row>
        <el-col :span="12">
          <dv-border-box-11 title="各工区外委完成情况" ref="chart">
            <div style="height: 300px;padding-top:40px;" id="chart"></div>
          </dv-border-box-11>
        </el-col>
        <el-col :span="12">
          <dv-border-box-11 title="各外委厂家完成情况" ref="customer">
            <div style="height: 300px;padding-top:40px;" id="customer"></div>
          </dv-border-box-11>
        </el-col>
      </el-row>

      <!-- 页面主表格 -->
      <dv-border-box-11 title="外委明细数据" ref="datagrid">
        <div id="gridWrapper" style="padding: 30px;padding-top:60px;padding-bottom:10px;">
          <div id="datagrid">
            <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
              element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column label="外委厂家" prop="customername" width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="工区" prop="fromworkcentername" width="120" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="零件号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
              </el-table-column>
              <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
              <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
              <el-table-column label="外委工序" prop="outstepname" width="120" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="工序号" prop="specno" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="工时" prop="durationperunit" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="转出人" prop="outerson" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="转出时间" prop="outdate" width="100" :formatter="splitDate"></el-table-column>
              <el-table-column label="转出数" prop="outqty" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="转入人" prop="inperson" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="转入时间" prop="indate" width="100" :formatter="splitDate"></el-table-column>
              <el-table-column label="状态" prop="status" width="80" show-overflow-tooltip>
                <template slot-scope="scope">
                  <el-tag effect="dark" v-if="scope.row.status === '已返回'" type="success">{{scope.row.status}}
                  </el-tag>
                  <el-tag effect="dark" v-else>{{scope.row.status}}</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="合格数" prop="acceptanceqty" width="80" show-overflow-tooltip></el-table-column>
              <el-table-column label="报废数" prop="lossqty" width="80" show-overflow-tooltip></el-table-column>
            </el-table>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="queryInfo.currentPage" :page-sizes="[10,18,50,100]" :page-size="queryInfo.pageSize"
              layout="prev,pager,next,jumper,sizes,total" :total="total">
            </el-pagination>
            <el-backtop></el-backtop>
          </div>
        </div>
      </dv-border-box-11>

      <!-- 工区外委明细 -->
      <el-dialog :title="workcenterDetail.title" :width="'98%'" :top="'10px'"
        :visible.sync="workcenterDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="workcenterDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="外委厂家" prop="customername" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="工区" prop="fromworkcentername" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="零件号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
          </el-table-column>
          <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="外委工序" prop="outstepname" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="工序号" prop="specno" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="工时" prop="durationperunit" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转出人" prop="outerson" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转出时间" prop="outdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="转出数" prop="outqty" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转入人" prop="inperson" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转入时间" prop="indate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === '已返回'" type="success">{{scope.row.status}}</el-tag>
              <el-tag v-else>{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="合格数" prop="acceptanceqty" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="报废数" prop="lossqty" width="80" show-overflow-tooltip></el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleWorkcenterDetailCurrentChange"
          :current-page="workcenterDetail.queryInfo.currentPage" :page-size="workcenterDetail.queryInfo.pageSize"
          :page-sizes="[workcenterDetail.queryInfo.pageSize]" layout="prev,pager,next,jumper,sizes,total"
          :total="workcenterDetail.total">
        </el-pagination>
      </el-dialog>

      <!-- 各外委厂商明细 -->
      <el-dialog :title="customerDetail.title" :width="'98%'" :top="'10px'"
        :visible.sync="customerDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="customerDetail.dataList" stripe border>
          <el-table-column type="index" width="50"></el-table-column>
          <el-table-column label="外委厂家" prop="customername" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="工区" prop="fromworkcentername" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="零件号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
          </el-table-column>
          <el-table-column label="批次号" prop="containername" show-overflow-tooltip></el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="外委工序" prop="outstepname" width="120" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="工序号" prop="specno" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="工时" prop="durationperunit" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转出人" prop="outerson" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转出时间" prop="outdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="转出数" prop="outqty" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转入人" prop="inperson" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="转入时间" prop="indate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="状态" prop="status" width="80" show-overflow-tooltip>
            <template slot-scope="scope">
              <el-tag v-if="scope.row.status === '已返回'" type="success">{{scope.row.status}}</el-tag>
              <el-tag v-else>{{scope.row.status}}</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="合格数" prop="acceptanceqty" width="80" show-overflow-tooltip></el-table-column>
          <el-table-column label="报废数" prop="lossqty" width="80" show-overflow-tooltip></el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleCustomerDetailCurrentChange"
          :current-page="[customerDetail.queryInfo.currentPage]" :page-size="customerDetail.queryInfo.pageSize"
          :page-sizes="[customerDetail.queryInfo.pageSize]" layout="prev,pager,next,jumper,sizes,total"
          :total="customerDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { getParams, exportExcelData } from '../Scripts/hooks/useCommonMethod.js'
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { getFactoryListByCode, getCustomerList, getUserInfo } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2BoardHeader from '../Scripts/components/Vue2BoardHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2BoardHeader },
      data: {
        splitDate,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          factoryid: '',
          factoryname: '',
          customerid: '',
          selectdate: '',
          currentPage: 1,
          pageSize: 10
        },
        total: 0,
        dataList: [],
        factoryList: [],
        customerList: [],
        workcenterDetail: {
          dialogVisiable: false,
          queryInfo: { workcentername: '', status: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        customerDetail: {
          dialogVisiable: false,
          queryInfo: { customername: '', status: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        userInfo: {},
        title: '',
        rules: { selectdate: [{ required: true, message: '外委时间不能为空', trigger: 'change' }] },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 各工区外委完成情况
        async getWorkcenterData() {
          const loadingOption = { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' };
          const dom = document.getElementById("chart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(loadingOption);

          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerCommissionDashBoard.ashx?action=getWorkcenterData', {
            type: 'getWorkcenterData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrWorkcenter = [], arrTotal = [], arrInQty = [];
          for (const i of data) {
            arrWorkcenter.push(i.fromworkcentername);
            arrTotal.push(i.total);
            arrInQty.push(i.inqty);
          }

          let option = barOption({ isLableFormat: true, provideNumber: 4 });
          option.legend.data = ['总数', '已返回'];//设置图例文字
          option.xAxis.data = arrWorkcenter;//x轴数据
          option.yAxis[1].show = false;//隐藏第二y轴

          option.series[0] = _.merge(option.series[0], {
            name: '总数', data: arrTotal,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '已返回', data: arrInQty,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.chart.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            if (params.value == 0) { return; }
            this.workcenterDetail.queryInfo.currentPage = 1;
            this.workcenterDetail.queryInfo.workcentername = params.name;
            this.workcenterDetail.queryInfo.status = params.seriesName;
            this.workcenterDetail.title = `【${params.name}】外委【${params.seriesName}】明细`
            this.workcenterDetail.dialogVisiable = true
            this.getWorkcenterDetail();
          })
        },
        //  各外委厂家完成情况
        async getCustomerData() {
          const loadingOption = { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff', color: '#66b1ff' };
          const dom = document.getElementById("customer");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(loadingOption);

          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerCommissionDashBoard.ashx?action=getCustomerData', {
            type: 'getCustomerData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrWorkcenter = [], arrTotal = [], arrInQty = [];
          for (const i of data) {
            arrWorkcenter.push(i.customername);
            arrTotal.push(i.total);
            arrInQty.push(i.inqty);
          }

          let option = barOption({ isLableFormat: true, provideNumber: 4 });
          option.legend.data = ['总数', '已返回'];//设置图例文字
          option.xAxis.data = arrWorkcenter;//x轴数据
          option.yAxis[1].show = false;//隐藏第二y轴

          option.series[0] = _.merge(option.series[0], {
            name: '总数', data: arrTotal,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          option.series[1] = _.merge(_.cloneDeep(option.series[0]), {
            name: '已返回', data: arrInQty,
            label: { color: colorList.green.color },
            itemStyle: { color: { colorStops: colorList.green.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.customer.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            if (params.value == 0) { return; }
            this.customerDetail.queryInfo.currentPage = 1;
            this.customerDetail.queryInfo.customername = params.name;
            this.customerDetail.queryInfo.status = params.seriesName;
            this.customerDetail.title = `【${params.name}】外委【${params.seriesName}】明细`;
            this.customerDetail.dialogVisiable = true
            this.getCustomerDetail();
          })
        },
        // 工区外委明细
        async getWorkcenterDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerCommissionDashBoard.ashx?action=getWorkcenterDetail', {
            type: 'getWorkcenterDetail',
            ...this.queryInfo,
            ...this.workcenterDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.workcenterDetail.dataList = data;
          this.workcenterDetail.total = total;
        },
        // 查询外委厂家明细
        async getCustomerDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerCommissionDashBoard.ashx?action=getCustomerDetail', {
            type: 'getCustomerDetail',
            ...this.queryInfo,
            ...this.customerDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.customerDetail.dataList = data;
          this.customerDetail.total = total;
        },
        // 下方表格
        async getDetailData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerCommissionDashBoard.ashx?action=getDetailData', {
            type: 'getDetailData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.datagrid.initWH(); }, 300);
        },
        factorySeletChange() {
          this.queryInfo.factoryname = this.factoryList.filter(item => item.factoryid === this.queryInfo.factoryid)[0].factoryname;
          this.title = `${this.queryInfo.factoryname}外委统计看板`;
          document.title = this.title;
        },
        // 导出
        async getExportExcel() {
          const config = {
            url: '../handler/board/ContainerCommissionDashBoard.ashx?action=getExportExcel',
            data: { type: 'getExportExcel', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        handlerBtnSearch() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.getWorkcenterData();
              this.getDetailData();
              this.getCustomerData();
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getDetailData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getDetailData();
        },
        handleWorkcenterDetailCurrentChange(newPage) {
          this.workcenterDetail.queryInfo.currentPage = newPage;
          this.getWorkcenterDetail();
        },
        handleCustomerDetailCurrentChange(newPage) {
          this.customerDetail.queryInfo.currentPage = newPage;
          this.getCustomerDetail();
        }
      },
      async mounted() {
        const today = dayjs().format('YYYY-MM-DD');
        const startOfThisMonth = dayjs().startOf('month').format('YYYY-MM-DD');
        const endOfThisMonth = dayjs().endOf('month').format('YYYY-MM-DD');
        this.queryInfo.selectdate = [startOfThisMonth, endOfThisMonth];

        this.customerList = await getCustomerList();//查询外委厂家
        this.factoryList = await getFactoryListByCode({ factoryCode: '604|601|607|609|600|608|602' });//查询分厂列表
        this.userInfo = await getUserInfo({ employeeid: getParams("uid") });

        if (this.userInfo.factoryid && this.factoryList.some(item => item.factoryid === this.userInfo.factoryid)) {
          const { factoryid, factoryname } = this.userInfo;
          this.queryInfo.factoryid = factoryid;
          this.queryInfo.factoryname = factoryname;
        } else {
          this.queryInfo.factoryid = this.factoryList[0].factoryid;
          this.queryInfo.factoryname = this.factoryList[0].factoryname;
        }
        this.title = `${this.queryInfo.factoryname}外委统计看板`;
        document.title = this.title;
        this.getWorkcenterData();
        this.getDetailData();
        this.getCustomerData();
      }
    })
  </script>
</body>

</html>